package com.wardrobe.soa.api.goods;

import com.wardrobe.domain.goods.GoodsShowBean;
import com.wardrobe.soa.common.ApiResult;
import com.wardrobe.soa.utils.CommonConsant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by Administrator on 2018/11/20.
 */
@RestController
@RequestMapping("/api/goods")
public class GoodsController {
    private static final Logger logger = LoggerFactory.getLogger(GoodsController.class);
    @Autowired
    private GoodsService goodsService;

    @RequestMapping("/getGoodsDetail")
    public ApiResult getGoodsDetail(long id,long userId){
        try {
            GoodsResponse goodsDetail = goodsService.getGoodsDetail(id,userId);
            return new ApiResult(CommonConsant.successCode,CommonConsant.success,CommonConsant.successMsg,goodsDetail);
        }catch (Exception e){
            logger.error("getGoodsDetail",e);
        }
        return new ApiResult(CommonConsant.serverFailedCode,CommonConsant.failed,CommonConsant.serverFailedMsg,"");
    }

    @RequestMapping("/getSearchGoodsList")
    public ApiResult getSearchGoodsList(String goodName){
        try {
            List<GoodsShowBean> list = goodsService.getSearchGoodsList(goodName);
            return new ApiResult(CommonConsant.successCode,CommonConsant.success,CommonConsant.successMsg,list);
        }catch (Exception e){
            logger.error("getSearchGoodsList",e);
        }
        return new ApiResult(CommonConsant.serverFailedCode,CommonConsant.failed,CommonConsant.serverFailedMsg,"");
    }

    @RequestMapping("/getHotGoodsList")
    public ApiResult getHotGoodsList(){
        try {
            List<GoodsShowBean> list = goodsService.getHotGoodsList();
            return new ApiResult(CommonConsant.successCode,CommonConsant.success,CommonConsant.successMsg,list);
        }catch (Exception e){
            logger.error("getHotGoodsList",e);
        }
        return new ApiResult(CommonConsant.serverFailedCode,CommonConsant.failed,CommonConsant.serverFailedMsg,"");
    }
}
